package com.atguigu.study.controller;

import com.atguigu.study.annotations.MethodExporter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @auther zzyy
 * @create 2024-12-04 21:37
 */

@RestController
@Slf4j
public class AopV2Controller
{
    //http://localhost:2404/list?page=1&rows=5
    @MethodExporter
    @GetMapping(value = "/list")
    public Map list(@RequestParam("page") int page, @RequestParam("rows")  int rows)
    {
        Map<String,String> result = new LinkedHashMap<>();
        result.put("code","200");
        result.put("message","success");


        //暂停毫秒
        try { TimeUnit.MILLISECONDS.sleep(new Random().nextInt(1000)); } catch (InterruptedException e) { e.printStackTrace(); }

        return result;
    }

    //http://localhost:2404/get
    @MethodExporter
    @GetMapping(value = "/get")
    public Map get()
    {
        Map<String,String> result = new LinkedHashMap<>();
        result.put("code","404");
        result.put("message","not-found");

        //暂停毫秒
        try { TimeUnit.MILLISECONDS.sleep(new Random().nextInt(1000)); } catch (InterruptedException e) { e.printStackTrace(); }

        return result;
    }

}

